<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/top.jsp" %>

	<div class="sub">
		<div class="sub_left">
			
			<ul>
				<c:forEach var = "menuList" items="${menuList}">
					<li><a href="#" <c:if test="${menuList.menuIndex == menu.menuIndex}"> class="menu_on" </c:if> onClick="goBoardListMain(<c:out value="${menuList.menuIndex}" />)"><c:out value="${menuList.menuName}" /></a></li>				
				</c:forEach>
			</ul>
		</div>
		<div class="sub_content">
			<div class="title">
				<div class="tit"><c:out value="${menu.menuName}"/><%-- <img src="${imgUrl}/sub_tit4.jpg" border="0" /> --%></div>
				<div class="home">HOME > <font color="#4a7ed5"><c:out value="${menu.menuName}" /></font></div>
			</div>
			<div class="content">
				<table border="0" cellspacing="0" cellpadding="0" width="100%" class="notice_list">
					<tr>
						<td height="3" bgcolor="#4a7ed5" colspan="4"></td>
					</tr>
					<tr>
						<td width="60" height="38"><font color="#4a7ed5"><b>NO.</b></font></td>
						<td width="488"><font color="#4a7ed5"><b>제목</b></font></td>
						<td width="60"><font color="#4a7ed5"><b>등록자수</b></font></td>
						<td width="110"><font color="#4a7ed5"><b>누적금액</b></font></td>
						<td width="1"><font color="#4a7ed5"><b></b></font></td>
					</tr>
					<tr>
						<td height="1" bgcolor="#4a7ed5" colspan="4"></td>
					</tr>
					<table border="0" cellspacing="0" cellpadding="0" width="100%" class="notice_list" id="boardList">
					
					</table>
					<table border="0" cellspacing="0" cellpadding="0" width="100%" class="notice_list">
					<tr>
						<td height="1" bgcolor="#4a7ed5" colspan="4"></td>
					</tr>
					<tr>
						<td height="10"></td>
					</tr>
					<tr>
						<td colspan="4" align="center">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="36" align="left" id="firstLeft"></td>
								<td width="33" align="left" id="left"></td>
								<td class="sub_page" id="cur"></td>
								<td width="33" align="right" id="right"></td>
								<td width="36" align="right" id="endRight"></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td height="20"></td>
					</tr>
					<tr>
						<td colspan="4" class="sub_search" align="center">
						<FORM name="fsearch" style="margin: 0px;" method="post" onkeydown="hitEnterKey(event)" onsubmit="return false;">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><img src="${imgUrl}/search_tit.jpg" border="0" /></td>
								<td><select name="searchType"><option value="1">본문</option><option value="2">제목</option></select></td>
								<td width="5"></td>
								<td><input type="text" id="searchName" /></td>
								<td width="5"></td>
								<td><img src="${imgUrl}/search_btn.jpg" border="0" onClick="getSearchBoardList()" /></td>
							</tr>
						</table>
						</FORM>
						</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
<form  id="frm" name="frm" method="post" style="display:none;">
	<input type="text" name="menuIndex" id="menuIndex" value="${menu.menuIndex}">
	<input type="text" name="textID" id="paramTextID">
	<input type="text" name="mode" id="mode">
</form>
<script type="text/javascript">
  var _this = this;
  var markerSetting = {
  		paging:{}
  }
  init();
  function init() {
  		markerSetting.paging.page = '<c:out value="${totalPage.page}"/>';
		markerSetting.paging.totalPage ='<c:out value="${totalPage.totalPage}"/>';
		markerSetting.paging.nowSeq = 1;
		markerSetting.paging.menuIndex = $("#menuIndex").val();
		getBoardList();
  }
  
  function getBoardList() {
	  	var url='/board/getBoardList.json';
  	
		var param=markerSetting.paging;
		var list="";
		AjaxPost(url, param, function(data){
//	 		jsonLog(data.boardList);
			$.each(data.boardList,function(index, value){
				list += "<tr>";
				list += "	<td width='60' height='33'><font color=''#333333' id='textNum'>"+value.textNum+"</font></td>";
				list += "	<td width='488' id='title' align='left'><a href='#' onClick='boardView("+value.textID+")'>"+value.title+"</a></td>";
				list += "	<td width='60' id='regiTime'><font color='#3885d7'><b>"+value.proCnt+"명</b></font></td>";
				list += "	<td width='110' id='sumPoint'><font color='#cf5050'><b>"+value.sumPoint+"원</b></font></td>";
				list += "	<td width='1' style='diplay:none'><input type='hidden' value="+value.textID+" id='textID'></td>";
				list += "</tr>";
				list += "<tr>";
				list += "	<td height='1' bgcolor='#cbcbcb' colspan='5'></td>";
				list += "</tr>";
			});
			$("#boardList").html(list);
			$("#boardList > tr").each(function() {
				$(this).css("cursor", "hand");
			});
			markerSetting.paging.totalPage= data.totalPage.totalPage;
			makePaging();
		});
  }
  
  function getSearchBoardList() {
	  markerSetting.paging.searchType = $("select[name=searchType]").val();
	  markerSetting.paging.searchName = $("#searchName").val();
	  
	  getBoardList();
  }
  function makePaging() {
  	$('#pagenation').html("");
		var totalPage = markerSetting.paging.totalPage;
		var nowPage = markerSetting.paging.page;
		var html='';
		var firstLeft="", left="", cur = "", right="", endRight="";
		var setFunctionName='';
		var index=(nowPage-10);
		var indexCount=0;
		
		var endPage = totalPage / 10;
		if (totalPage % 10 > 0) {
			endPage = endPage + 1;
		}
		
		if(index>1){
			firstLeft+='<a onclick="changePaging(1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_12.jpg"/ boarder=0></a>';
			left+='<a onclick="changePaging('+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_11.jpg"/  border=0></a>';
		}
//		//logs('totalPage/20 = '+totalPage/20);
		for(;index<=endPage;index++){
			if((index)==nowPage){
				setFunctionName='';
			}else{
				setFunctionName=' onclick="changePaging('+index+')"';
			}
			
			if(index>0){
					
				if(index == nowPage) {
					cur+='<a hrer="#" '+setFunctionName+' class=\'sub_page_on\'>'+index+'</a>';
				} else {
					cur+='<a href="#" '+setFunctionName+'>'+index+'</a>';
				}
				
				indexCount++;
			}
			if(indexCount>9){
				right+='<a onclick="changePaging('+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_r1.jpg"/ border=0></a>';
				endRight+='<a onclick="changePaging('+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/page_btn_r2.jpg"/ border=0></a>';
				break;
			}
			
		}
		$("#firstLeft").html(firstLeft);
		$("#left").html(left);
		$("#cur").html(cur);
		$("#right").html(right);
		$("#endRight").html(endRight);
  }
  
  function changePaging(index, option){
		logs('markerSetting.paging.totalPage = '+markerSetting.paging.totalPage);
		if(option==null){
			logs(', index = '+index);
			
			markerSetting.paging.page=index;
			markerSetting.paging.start=0;
			markerSetting.paging.end=0;
			getBoardList();
		}else{
			if(option=='before'){
				var next = index-9;
				while(next<=0){
					next++;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}else if(option=='after'){
				var next = index+9;
				while(next>=(markerSetting.paging.totalPage/10)+1){
					next--;
				}
				logs('next = '+next+', index = '+index);
				markerSetting.paging.page=next;
				markerSetting.paging.start=0;
				markerSetting.paging.end=0;
				getBoardList();
			}
		}
	}
	
	function adminBoardWrite() {
		$("#mode").val("insert");
	  	$("#frm").attr("action", "/admin/adminBoardWrite");
		$("#frm").submit();
  	}
	function goBoardListMain(type) {
		// type = 1 공지사항
			// type = 2 최신판례
			// type = 3 최신법령
			// type = 4 A항목
			// type = 5 B항목
			// type = 6 C항목
			// type = 7 D항목
			// type = 8 E항목
			// type = 9 F항목
			// type = 10 G항목
			// type = 11 H항목
			$("#menuIndex").val(type);
			var url = "/board/boardListMain";	
			$("#frm").attr("action", url);
			$("#frm").submit();
			
			return false;
	 }
	 function boardView(textID) {
	  //로그인 체크
		<% if(session.getAttribute(UserModel.USER_SESSION_INFO) == null) {%>
			$("#paramTextID").val(textID);
			$("#frm").attr("action", "/board/userBoardView");
		  	$("#frm").submit();
		  	return;
		<% }%>
		
		var myPoint = 0, boardPoint = 0;
		var isUseCheck = "N";
		
		var url='/board/getMyInfo.json';
		var param = "textID="+textID+"&menuIndex="+$("#menuIndex").val();
		
		AjaxPost(url, param, function(data){
			myPoint = data.userData.point; //내 금액
			boardPoint = data.boardData.usePoint; //게시글의 구매금액
			isUseCheck = data.usePointCheck; //구매체크
			
			<% if(!"40".equals(session.getAttribute(UserModel.USER_LEVEL))){ %>
			if(myPoint < boardPoint) {
				alert('포인트가 부족합니다.');
				return;			
			}
			
			if(isUseCheck != 'Y') {
				if(!confirm('구매 하시겠습니까?')) {
					return;
				}
			}
			<% } %>
			$("#paramTextID").val(textID);
			$("#frm").attr("action", "/board/boardView");
		  	$("#frm").submit();
		});	
	  	
	  	return false;
	  }
	 function hitEnterKey(e){
		  if(e.keyCode == 13){
			  getSearchBoardList();			  
			  return false;
		  }
	   } 
</script>
<%@ include file="/WEB-INF/views/include/bottom.jsp" %>